package top.huiwow.managers;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

import java.util.UUID;

public class GamePlayer {
    final UUID uuid;
    public boolean controlledStats = false;
    private int strength;
    private int speed;
    private int mana;
    private int critDamage;
    private int critChance;
    private int intelligence;
    private int defense;

    public GamePlayer(UUID uuid) {
        this.uuid = uuid;
        strength = 0;
        speed = 100;
        defense = 0;
        intelligence = 200;
        mana = intelligence;
        critChance = 30;
        critDamage = 0;
    }

    public int getMana() {
        return mana;
    }

    public void setMana(int mana) {
        this.mana = Math.min(mana, this.intelligence);
    }

    public void addMana(int amount) {
        this.mana += amount;
    }

    public void reduceMana(int amount) {
        this.mana -= amount;
    }

    public int getCritDamage() {
        return critDamage;
    }

    public void setCritDamage(int critDamage) {
        this.critDamage = critDamage;
    }

    public int getCritChance() {
        return critChance;
    }

    public void setCritChance(int critChance) {
        this.critChance = critChance;
    }

    public int getIntelligence() {
        return intelligence;
    }

    public void setIntelligence(int intelligence) {
        this.intelligence = intelligence;
    }

    public int getStrength() {
        return strength;
    }

    public void setStrength(int strength) {
        this.strength = strength;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
        this.getPlayer().setWalkSpeed(speed / 100f * 0.2f);
    }

    public int getDefense() {
        return defense;
    }

    public void setDefense(int defense) {
        this.defense = defense;
    }

    public Player getPlayer() {
        return Bukkit.getPlayer(uuid);
    }

    public String printPlayerStats() {
        return buildLine("Strength", strength) +
                buildLine("Speed", speed) +
                buildLine("Defense", defense) +
                buildLine("Intelligence", intelligence) +
                buildLine("Mana", mana) +
                buildLine("Crit Chance", critChance) +
                buildLine("Crit Damage", critDamage) +
                buildLine("Health", getPlayer().getHealth()) +
                buildLine("Max Health", getPlayer().getMaxHealth());
    }

    String buildLine(String name, int value) {
        return ChatColor.RED.toString() + ChatColor.BOLD + name + ChatColor.RESET + ":  " + ChatColor.GREEN + value + ChatColor.RESET + "\n";
    }

    String buildLine(String name, double value) {
        return ChatColor.RED.toString() + ChatColor.BOLD + name + ChatColor.RESET + ":  " + ChatColor.GREEN + value + ChatColor.RESET + "\n";
    }

}
